package com.lagou.studentsystem.servlet;

import com.lagou.studentsystem.model.Student;
import com.lagou.studentsystem.service.StudentService;
import com.lagou.studentsystem.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "FindStudentAllServlet",urlPatterns = "/findStudentAll")
public class FindStudentAllServlet extends HttpServlet {

    private StudentService studentService = new StudentServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        List<Student> studentList = studentService.getStudentAll();
                if (null != studentList) {
                    request.getSession().setAttribute("studentList", studentList);
                    response.sendRedirect("main.jsp");
                }
            }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
